<tagLib name="lbase"/>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>微信公众平台管理系统</title>
        <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
    <include file="Public:header" />
    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="__PUBLIC__/js/html5.js"></script>
    <![endif]-->
</head>

<!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->
<!--[if IE 7 ]> <body class="ie ie7 "> <![endif]-->
<!--[if IE 8 ]> <body class="ie ie8 "> <![endif]-->
<!--[if IE 9 ]> <body class="ie ie9 "> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> 
<body class="">
    <!--<![endif]-->

    <!--顶部菜单-->
<include file="Public:navbar" />

<!--左侧导航条-->
<include file="Public:nav" />

<!--右侧整体区域-->
<div class="content">
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="row-fluid">
                <!--右侧栏目区域start-->
                <div class="block">
                    <a class="block-heading" data-toggle="collapse">新增用户</a>
                    <div class="block-body collapse in">

                        <div class="container-fluid" style="margin-top: 10px;">
                            <!--右侧栏目内容区域start-->
                            <div class="row">
                                <div class="span12">
                                    <div class="pull-left">
                                        <a href="{:U('/'.$module_name)}" class="btn btn-primary">返回</a>&nbsp;&nbsp;
                                    </div>
                                </div>
                                <!--右侧字段区域start-->
                                <div class="span12" style="margin-top:10px;">
                                    <form class="form-horizontal" method="post">
                                        <fieldset>
                                            <div id="legend" class="">
                                                <legend class=""></legend>
                                            </div>
                                            <div class="control-group">
                                                <label class="control-label" for="input01">用户名</label>
                                                <div class="controls">
                                                    <input type="text" placeholder="" name="user_name" class="input-xlarge">
                                                    <p class="help-block">登录用户名，英文字母</p>
                                                </div>
                                            </div>

                                            <div class="control-group">
                                                <label class="control-label" for="input01">昵称</label>
                                                <div class="controls">
                                                    <input type="text" placeholder="" name="title" class="input-xlarge">
                                                    <p class="help-block">用户昵称，方便后期管理</p>
                                                </div>
                                            </div><div class="control-group">
                                                <label class="control-label" for="input01">登录密码</label>
                                                <div class="controls">
                                                    <input type="password" placeholder="" name="user_pwd" class="input-xlarge">
                                                    <p class="help-block">6位以上字母+数字</p>
                                                </div>
                                            </div>

                                            <div class="control-group">
                                                <label class="control-label" for="input01">确认密码</label>
                                                <div class="controls">
                                                    <input type="password" placeholder="" name="user_pwd_confirm" class="input-xlarge">
                                                    <p class="help-block">请确认登录密码</p>
                                                </div>
                                            </div>

                                            <div class="control-group">
                                                <label class="control-label">状态</label>
                                                <div class="controls">
                                                    <label class="radio inline">
                                                        <input type="radio" name="status" value="1" checked="checked">
                                                        启用
                                                    </label>
                                                    <label class="radio inline">
                                                        <input type="radio" value="0" name="status">
                                                        禁用
                                                    </label>
                                                </div>
                                            </div>

                                            <div class="control-group">
                                                <label class="control-label">备注</label>
                                                <div class="controls">
                                                    <div class="textarea">
                                                        <textarea type="" class="" name="remark"></textarea>
                                                    </div>
                                                </div>
                                            </div>
                                            <div id='pop'></div>

                                            <div class="form-actions">
                                                <button type="button" class="btn btn-primary" id='save'>保 存</button>&nbsp;&nbsp;
                                                <a class="btn" href="{$pre_url}">返 回</a>
                                            </div>
                                        </fieldset>
                                    </form>
                                </div>
                                <!--右侧字段区域end-->
                            </div>
                            <!--右侧栏目内容区域end-->
                        </div>

                    </div>
                </div>
                <!--右侧栏目区域end-->
            </div>
            <footer>
                <include file="Public:footer" />
            </footer>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function() {
        var save_button = $('#save');
        save_button.click(function() {
            if (check_fields()) {
                ajax_action();
            }
        });

        function ajax_action() {
            var data = $('form').serialize();
            save_button.attr('disabled', 'disabled');
            $.ajax({
                type: "POST",
                url: app_url + "/" + module_name + "/insert",
                data: data,
                dataType: 'json',
                cache: false,
                success: function(data) {
                    success(data);
                },
                error: function() {
                    error();
                }
            });
        }

        function check_fields() {
            if ($("[name=user_name]").val() == '') {
                alert('请填写用户名!');
                $("[name=user_name]").focus();
                return false;
            }
            if ($('[name=user_pwd]').val() == '') {
                alert('请填写登录密码!');
                $("[name=user_pwd]").focus();
                return false;
            }
            if ($('[name=user_pwd]').val() != $('[name=user_pwd_confirm]').val()) {
                alert('您两次填写的登陆密码不一致,请检查后重新输入!');
                $('[name=user_pwd]').val('');
                $('[name=user_pwd_confirm]').val('');
                $("[name=user_pwd]").focus();
                return false;
            }
            return true;
        }

        $('#pop').ajaxStart(function() {
            $('#pop').html('<div class="alert alert-info"><button type="button" class="close" data-dismiss="alert">×</button>数据请求中，请稍候...</div>')
                    .fadeIn("slow");
        });

        function success(data) {
            switch (data.data) {
                case 1:
                    $('#pop').html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>信息添加成功！</div>')
                            .fadeIn("slow");
                    break;
                case 2:
                    $('#pop').html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>两次密码输入的不一致,请重新输入!</div>')
                            .fadeIn("slow")
                            .fadeOut(5000);
                    save_button.removeAttr('disabled');
                    break;
                default:
                    $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>信息添加失败！</div>')
                            .fadeIn("slow");
            }
        }


        function error() {
            $('#pop').html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>远程服务器请求失败！</div>')
                    .fadeIn("slow")
                    .fadeOut(5000);
        }
    });
</script>
</body>
</html>


